package cn.darkhorse.core.param;


import cn.darkhorse.entity.BpmnWorkflowParam;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author yuanjun
 * @since 2020/6/3 15:32
 */
public class WorkflowParamAnalysis {
    private ParamParserStrategyFactory strategyFactory;

    public WorkflowParamAnalysis(ParamParserStrategyFactory strategyFactory) {
        this.strategyFactory = strategyFactory;
    }

    public <T> Map<String, Object>  doAnalysis(List<BpmnWorkflowParam> paramList, Class<T> tClazz, T form,String userName){
        Map<String, Object> resultMap = new HashMap<>(16);

        for (BpmnWorkflowParam param : paramList) {
            IParamParserStrategy paramParserStrategy = strategyFactory.getParamParserStrategy(param.getParamClass());
            Map<String, Object> result = paramParserStrategy.parse(param,tClazz,form,userName);
            if (result == null) { continue; }

            resultMap.putAll(result);
        }

        return resultMap;
    }

    public ParamParserStrategyFactory getStrategyFactory() {
        return strategyFactory;
    }
}
